#include "crc.h"

uint8_t SHT3X_CalcCrc(uint8_t data[], uint8_t nbrOfBytes)
{

    uint8_t bit;        // bit mask
    uint8_t crc = 0xFF; // calculated checksum
    uint8_t byteCtr;    // byte counter
  
    /* calculates 8-Bit checksum with given polynomial*/
    for(byteCtr = 0; byteCtr < nbrOfBytes; byteCtr++)
    {
      crc ^= (data[byteCtr]);
      for(bit = 8; bit > 0; --bit)
      {
        if(crc & 0x80) crc = (crc << 1) ^ POLYNOMIAL;
        else           crc = (crc << 1);
      }
    }
	
	   return crc;
}




